<?php

namespace App\Http\Controllers;

use App\Models\Rank;
use App\Models\User;
use Exception;
use Illuminate\Http\Request;

/**
 * 团利创客
 */
class MakerController extends Controller
{
    /**
     * 创客信息
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function maker_info(Request $request)
    {
        try {
            $status = 0;
            $data   = [];
            $userID = $request->get('user_id');
            if (empty($userID)) {
                throw new Exception('缺少参数');
            }

            $user = User::where(['userID' => $userID])->first();
            //创客等级名称
            $rank         = Rank::where(['level' => $user->level])->first();
            $data['name'] = $rank->name;
            //当前财富值
            $data['value'] = $user->empirical_value;
            //创客过期时间
            $data['overdue_time'] = date('Y-m-d', strtotime('+1 year', $user->register_time));
            //当前等级的上下限
            $data['value_up']    = $rank->value_up;
            $data['value_below'] = $rank->value_below;

            $status = 1;
            $msg    = '查询成功';
        } catch (Exception $e) {
            $msg = $e->getMessage();
        }

        return response()->json(['status' => $status, 'msg' => $msg, 'data' => $data]);
    }

    /**
     * 申请成为创客
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function apply_maker(Request $request)
    {
        try {
            $status = 0;
            $data   = [];

            $status = 1;
            $msg    = '查询成功';
        } catch (Exception $e) {
            $msg = $e->getMessage();
        }

        return response()->json(['status' => $status, 'msg' => $msg, 'data' => $data]);
    }
}
